#include "task_bspInit.h"
#include "tasksInit.h"

#include <stdio.h>

#include "los_task.h"
// #include "los_memory.h"

#include "bsp_led.h"
#include "bsp_beep.h"
#include "bsp_key.h"
#include "bsp_oled.h"
#include "bsp_I2C.h"
#include "bsp_e53.h"
#include "bsp_sl2823.h"
#include "bsp_tapeLight.h"
#include "bsp_gpioDev.h"
#include "bsp_mq2.h"
// #include "bsp_wifi.h"

// #include "cJSON.h"

unsigned int task_bspInit_id;
TSK_INIT_PARAM_S task_bspInit_handler = {
    (TSK_ENTRY_FUNC)task_bspInit,
    20,
    0,
    4096,
    "task_bspInit",
    0
};

// extern void lpcd_demo(void);



void task_bspInit(void)
{
    // LOS_TaskLock();

    // unsigned int ret = 0;

    // 1. ledInit()
    led_init();
    printf("----->led init ok\n");

    // 2. beepInit()
    beep_init();
    printf("----->beep init ok\n");

    // 3. keyinit
    key_adc_dev_init();
    printf("----->key init ok\n");

    // 4. oledinit
#if OLED_I2C_ENABLE
    oled_hw_i2c_init();
#else
    oled_sw_i2c_init();
#endif

    printf("----->oled gpio ok\n");

    // 5. e53init
    I2C_init();
    e53_ia_init();
    printf("----->e53 init ok\n");

    // 6. sl2823 init
    sl2823_init();

    //7. sg90_init
    sg90_init();

    //8. tapeLight init
    tapeLight_init_all();
    printf("----->tapeLight init ok\n");

    //9. gpioDev init
    gpioDev_init_all();

    //10. mq2 init
    mq2_init();

    //测试
    // tapeLight_test();
    // sg90_test();
    // sg90_setPWM_duty(12);
    // sl2823_test();

    // LOS_TaskUnlock();
    LOS_EventWrite(&bspInit_ECB, BSPINIT_EVENT_INITOK);
    // if error
    
    // TODO: 定时检查模块连接状态
    // while(1){}

    LOS_TaskDelete(LOS_CurTaskIDGet()); //删除自己
}




